﻿// (c) Copyright Mikhail Dikov. All other rights reserved.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI;
using WebPartExtenders;
using System.Xml.Serialization;
using System.ComponentModel;

namespace WebPartExtenderToolkit
{
    [ToolboxData("<{0}:DropShadowWebPart runat=server></{0}:DropShadowWebPart>")]
    [XmlRoot(Namespace = "DropShadowWebPart")]
    public class DropShadowWebPart : ExtenderWebPartBase
    {
        private DropShadowExtender extender;

        protected override void CreateChildControls()
        {            
            base.CreateChildControls();
            extender = new DropShadowExtender();
            Controls.Add(extender);
            ChildControlsCreated = true;
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            extender.TargetControlID = this.TargetControlID;
            extender.Enabled = Enabled && !string.IsNullOrEmpty(TargetControlID);
            extender.BehaviorID = this.BehaviorID;
            extender.ID = this.ID + "extender";
            extender.Width = ShadowWidth;
            extender.Opacity = Opacity;
            extender.TrackPosition = TrackPosition;
            extender.Rounded = Rounded; 
            //Always hide the extender control chrome, because it'll show up as an empty webpart
            ChromeType = PartChromeType.None;
            Title = "DropShadow WebPart Extender";

        }

        #region DropShadowExtender Properies

        [Category("Extender"),
        WebBrowsable(true),
        WebDisplayName("Shadow Width"),
        WebDescription("The width, in pixels of the drop shadow. Default value is 5."),
        Browsable(true), 
        Personalizable(PersonalizationScope.Shared),
        DisplayName("Shadow Width"),
        Description("The name of the CSS class to apply to the resize handle.")]
        public int ShadowWidth{ get; set; }

        [Category("Extender"),
        WebBrowsable(true),
        WebDisplayName("Opacity"),
        WebDescription("The opacity of the drop shadow, from 0 (fully transparent) to 1.0 (fully opaque). The default value is .5."),
        Browsable(true), 
        Personalizable(PersonalizationScope.Shared),
        DisplayName("Opacity"),
        Description("The opacity of the drop shadow, from 0 (fully transparent) to 1.0 (fully opaque). The default value is .5.")]
        public float Opacity{ get; set; }

        [Category("Extender"),
        WebBrowsable(true),
        WebDisplayName("TrackPosition"),
        WebDescription("Whether the drop shadow should track the position of the panel it is attached to. Use this if the panel is absolutely positioned or will otherwise move."),
        Browsable(true), 
        Personalizable(PersonalizationScope.Shared),
        DisplayName("TrackPosition"),
        Description("Whether the drop shadow should track the position of the panel it is attached to. Use this if the panel is absolutely positioned or will otherwise move.")]
        public bool TrackPosition{ get; set; }

        [Category("Extender"), 
        WebBrowsable(true),
        WebDisplayName("Rounded"),
        WebDescription("Set to true to set rounded corners on the target and the shadow. Default is false."),
        Browsable(true), 
        Personalizable(PersonalizationScope.Shared),
        DisplayName("Rounded"),
        Description("Set to true to set rounded corners on the target and the shadow. Default is false.")]
        public bool Rounded { get; set; }

	    #endregion

    }
}
